package cn.tedu.kuafu.Controller;

import cn.tedu.kuafu.entity.Admin;
import cn.tedu.kuafu.entity.User;
import cn.tedu.kuafu.mapper.AdminMapper;
import cn.tedu.kuafu.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class AdminController {
    @Autowired
    AdminMapper mapper;

    //
    @RequestMapping("/admin")
    public int login(@RequestBody Admin admin , HttpSession session){
        System.out.println("admin= " + admin);
        Admin u= mapper.selectByUsername(admin.getUsername());
        if (u!=null){
            if (admin.getPassword().equals(u.getPassword())){
                //把当前登录的用户对象保存到会话对象中
                session.setAttribute("admin",u);
                return 1;//登录成功
            }
            return 3;//密码错误
        }
        return 2;//用户名不存在
    }

}
